<?php
namespace Admin\Controller;
use Think\Controller;
/**
* 人员信息管理
*/
class PersonnelController extends Controller{
	/**
	 * 人员信息发布
	 */
	function ryAdd(){
        if ($_COOKIE['adminuser'] == NULL) {
            $this->error('请登录','/graduation/admin/user/login',1);
        }
		if (IS_POST) {
			$ryinfo = D('ryinfo');

			//图片上传
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 3145728 ;// 设置附件上传大小
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = './Application/Uploads/images/'; // 设置附件上传根目录
            $upload->savePath = ''; // 设置附件上传（子）目录
            // 上传文件
            $info = $upload->upload();
            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功
                //返回图片路径
                $img_path = '/graduation/Application/Uploads/images/' . $info['picture']['savepath'] . $info['picture']['savename'];

                //$ryinfo->picture = $img_path;
                $_POST['picture'] = $img_path;
                $_POST['addtime'] = time();
            }
            if (!$ryinfo->add(I('post.'))) {
            	$this->error($ryinfo->getError());
            }
			
			$this->redirect('personnel/ryList');
		}

		$this->assign('zcinfo',D('zcinfo')->select());
		$this->assign('zwinfo',D('zwinfo')->select());
		$this->display();
	}
	/**
	 * 人员信息管理
	 */
	public function ryList(){
        if ($_COOKIE['adminuser'] == NULL) {
            $this->error('请登录','/graduation/admin/user/login',1);
        }
		$ryinfo = D('ryinfo');
		if (IS_GET) {
			$list = $ryinfo->limit('10')->order('addtime desc')->page($_GET['p'].',10')->where("ry_name like '%".I('get.ry_name')."%' and ry_sex like '%".I('get.ry_sex')."%' and ry_minzu like '%".I('get.ry_minzu')."%' and ry_zhengzhi like '%".I('get.ry_zhengzhi')."%' and ry_join like '%".I('get.ry_join')."%' and ry_biye like '%".I('get.ry_biye')."%' and ry_xueli like '%".I('get.ry_xueli')."%' and ry_zhicheng like '%".I('get.ry_zhicheng')."%' and ry_zhiwu like '%".I('get.ry_zhiwu')."%' and ry_zaizhi like '%".I('get.ry_zaizhi')."%'")->select();
			$this->assign('list',$list);// 赋值数据集
			$count = $ryinfo->where("ry_name like '%".I('get.ry_name')."%' and ry_sex like '%".I('get.ry_sex')."%' and ry_minzu like '%".I('get.ry_minzu')."%' and ry_zhengzhi like '%".I('get.ry_zhengzhi')."%' and ry_join like '%".I('get.ry_join')."%' and ry_biye like '%".I('get.ry_biye')."%' and ry_xueli like '%".I('get.ry_xueli')."%' and ry_zhicheng like '%".I('get.ry_zhicheng')."%' and ry_zhiwu like '%".I('get.ry_zhiwu')."%' and ry_zaizhi like '%".I('get.ry_zaizhi')."%'")->count();// 查询满足要求的总记录数
			$Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
			$show = $Page->show();// 分页显示输出
			$this->assign('page',$show);// 赋值分页输出
			$this->assign('ryinfo',$list);// 赋值数据集

			$this->assign('zcinfo',D('zcinfo')->select());
			$this->assign('zwinfo',D('zwinfo')->select());
			$this->display();
		}else{
			// 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
			$list = $ryinfo->limit('10')->page($_GET['p'].',10')->select();
			$this->assign('list',$list);// 赋值数据集
			$count = $ryinfo->count();// 查询满足要求的总记录数
			$Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
			$show = $Page->show();// 分页显示输出
			$this->assign('page',$show);// 赋值分页输出
			$this->assign('ryinfo',$list);// 赋值数据集

			$this->assign('zcinfo',D('zcinfo')->select());
			$this->assign('zwinfo',D('zwinfo')->select());
			$this->display();
		}
	}
	//人员信息修改
	public function ryedit($id){
        if ($_COOKIE['adminuser'] == NULL) {
            $this->error('请登录','/graduation/admin/user/login',1);
        }
		if (IS_POST) {
			$ryinfo = D('ryinfo');
			//图片上传
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 3145728 ;// 设置附件上传大小
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = './Application/Uploads/images/'; // 设置附件上传根目录
            $upload->savePath = ''; // 设置附件上传（子）目录
            // 上传文件
            $info = $upload->upload();
            if(!$info) {// 上传错误提示错误信息
                //$this->error($upload->getError());
            }else{// 上传成功
                //返回图片路径
                $img_path = '/graduation/Application/Uploads/images/' . $info['picture']['savepath'] . $info['picture']['savename'];

                $ryinfo->picture = $img_path;
            }

			$ryinfo->where('id='.I('post.id'))->save();
			$ryinfo->where('id='.I('post.id'))->save(I('post.'));
			$this->redirect('personnel/ryList');
		}

		$this->assign('zcinfo',D('zcinfo')->select());
		$this->assign('zwinfo',D('zwinfo')->select());
		$this->assign('ryinfo',D('ryinfo')->find(I('get.id')));
		$this->display();
	}
	//人员信息删除
	public function rydel($id){
        if ($_COOKIE['adminuser'] == NULL) {
            $this->error('请登录','/graduation/admin/user/login',1);
        }
		if ($ryinfo = D('ryinfo')->delete($id)) {
			$this->redirect('personnel/ryList');
		}
	}
	//人员信息查看
	public function ryview($id){
        if ($_COOKIE['adminuser'] == NULL) {
            $this->error('请登录','/graduation/admin/user/login',1);
        }
		$this->assign('ryinfo',D('ryinfo')->find(I('get.id')));
		$this->display();
	}
}